home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
001
/
pibt3sp2.arc
/
PIBDIALB.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1985-09-25
|
19KB
|
558 lines
(*----------------------------------------------------------------------*)
(* Dial_A_Number --- dial phone number *)
(*----------------------------------------------------------------------*)
PROCEDURE Dial_A_Number( Re_Dial : BOOLEAN;
VAR Quit : BOOLEAN );
(*----------------------------------------------------------------------*)
(* *)
(* Procedure: Dial_A_Number *)
(* *)
(* Purpose: Dials phone number *)
(* *)
(* Calling Sequence: *)
(* *)
(* Dial_A_Number( Re_Dial : BOOLEAN; *)
(* VAR Quit : BOOLEAN ); *)
(* *)
(* Re_Dial --- TRUE to re-dial last number *)
(* Quit --- TRUE if Esc key hit to stop dialing *)
(* *)
(* Calls: Async_Send_String *)
(* Save_Screen *)
(* Restore_Screen *)
(* Draw_Menu_Frame *)
(* Reset_Global_Colors *)
(* Dialer_Carrier_Detect *)
(* Display_Phone_Numbers *)
(* TimeOfDay *)
(* TimeDiff *)
(* *)
(*----------------------------------------------------------------------*)
VAR
Dial_Title : ShortStr;
OK_Redial : BOOLEAN;
Ch : CHAR;
Timed_Out : BOOLEAN;
STimer : REAL;
Modem_Mess : AnyStr;
New_Baud : INTEGER;
Ierr : INTEGER;
Qerr : BOOLEAN;
Snumber : STRING[40];
Inumber : INTEGER;
Modem_Buzy : BOOLEAN;
Modem_NoC : BOOLEAN;
T : REAL;
TOD : REAL;
IY : INTEGER;
I : INTEGER;
J : INTEGER;
TS : STRING[9];
TSO : STRING[9];
ESC_Hit : BOOLEAN;
Local_Save_3 : Saved_Screen_Ptr;
Local_Save_5 : Saved_Screen_Ptr;
Got_Num : BOOLEAN;
BEGIN (* Dial_A_Number *)
Modem_Mess := '';
Manual_Dial := FALSE;
Quit := FALSE;
Got_Num := FALSE;
OK_Redial := Re_Dial AND ( Phone_Number <> '' );
IF OK_Redial THEN
Dial_Title := 'Redialing'
ELSE
Dial_Title := 'Dialing';
Save_Screen( Local_Save_5 );
IF NOT OK_Redial THEN
BEGIN (* Not a redial *)
Prefix_Str := '';
(* No dialing string given -- display *)
(* directory. *)
IF LENGTH( Dialing_String ) = 0 THEN
BEGIN
Display_Phone_Numbers( Phone_Number, Prefix_Str, Quit );
IF Dialer_Carrier_Detect OR Quit OR
( LENGTH( Phone_Number ) = 0 ) THEN
BEGIN
Restore_Screen( Local_Save_5 );
Reset_Global_Colors;
EXIT;
END
ELSE
Got_Num := TRUE;
END
ELSE (* Dialing string provided *)
BEGIN
Snumber := Dialing_String;
FOR I := 1 TO 25 DO
Phone_Entry_Data.Phone_Name[I] := ' ';
END;
IF ( NOT Quit ) THEN
BEGIN (* Phone number entered *)
IF ( NOT Got_Num ) THEN
BEGIN (* NOT Got_Num *)
IF UpCase( Snumber[1] ) = 'M' THEN
BEGIN
Manual_Dial := TRUE;
Snumber := COPY( Snumber, 2,
LENGTH( Snumber ) - 1 );
IF Snumber[1] IN ['+','-','!','@','#'] THEN
BEGIN
Prefix_Str := Phone_Prefix_Nos[ POS( Snumber[1],
'+-!@#' ) ];
Snumber := COPY( Snumber, 2,
LENGTH( Snumber ) - 1 );
END;
END;
IF Manual_Dial THEN
Phone_Number := Snumber
ELSE
BEGIN
Inumber := 2;
VAL( Snumber, Inumber, Ierr );
IF ( Ierr = 0 ) THEN
BEGIN
SEEK( Phone_File , Inumber - 1 );
READ( Phone_File , Phone_Entry_Data );
Phone_Number := Phone_Entry_Data.Phone_Number;
IF ( NOT Dialer_Carrier_Detect ) THEN
Reset_Comm_Params( Phone_Entry_Data );
END
ELSE
BEGIN
WRITELN;
WRITE('Bad phone number, dialing cancelled.');
ClrEol;
DELAY( Two_Second_Delay );
END;
END;
END (* NOT Got_Num *);
END (* Phone number entered *);
END (* Not a redial *);
IF ( Dialer_Carrier_Detect AND ( NOT Quit ) ) THEN
BEGIN
Save_Screen( Local_Save_3 );
Window( 1, 1, 80, 25 );
Draw_Menu_Frame( 10, 5, 60, 8, Menu_Frame_Color,
Menu_Text_Color + Blink, '' );
WRITE('Session already in progress, dialing aborted.');
DELAY( Two_Second_Delay );
Restore_Screen( Local_Save_3 );
Reset_Global_Colors;
Restore_Screen( Local_Save_5 );
Reset_Global_Colors;
EXIT;
END;
IF ( LENGTH( Phone_Number ) > 0 ) AND ( NOT Quit ) THEN
BEGIN (* Phone number gotten *)
Window( 1, 1, 80, 25 );
IF ( NOT Manual_Dial ) THEN
Dial_Title := TRIM( Dial_Title + ' ' +
Phone_Entry_Data.Phone_Name );
Draw_Menu_Frame( 10, 10, 60, 16, Menu_Frame_Color,
Menu_Text_Color, Dial_Title );
GoToXY( 1 , 1 );
(* Purge receive to avoid *)
(* false modem messages *)
Async_Purge_Buffer;
IF OK_Redial THEN
WRITE('Re-dialing: ', Prefix_Str + Phone_Number )
ELSE
WRITE('Dialing: ', Prefix_Str + Phone_Number );
ClrEol;
Async_Send_String( Modem_Dial + Prefix_Str + Phone_Number +
CHR( CR ) );
STimer := TimeOfDay;
Modem_Buzy := FALSE;
Modem_NoC := FALSE;
IY := WhereY;
TS := '';
GoToXY( 1 , 2 );
WRITE('Dialing begins at: ',TimeString(TimeOfDay));
ClrEol;
GoToXY( 1 , 3 );
WRITE('Elapsed dialing time: ');
ClrEol;
REPEAT
TOD := TimeOfDay;
T := TimeDiff( STimer , TOD );
TSO := TS;
TS := TimeString( T );
IF TS <> TSO THEN
BEGIN
GoToXY( 23 , 3 );
WRITE( TS );
ClrEol;
END;
Timed_Out := ( T > Modem_Time_Out );
IF Async_Receive( Ch ) THEN
Modem_Mess := Modem_Mess + Ch;
Modem_Buzy := ( POS( Modem_Busy , Modem_Mess ) > 0 ) AND
( LENGTH( Modem_Busy ) > 0 );
Modem_NoC := ( POS( Modem_No_Carrier , Modem_Mess ) > 0 ) AND
( LENGTH( Modem_No_Carrier ) > 0 );
Esc_Hit := FALSE;
IF KeyPressed THEN
BEGIN
READ( Kbd, Ch );
IF Ch = CHR( ESC ) THEN
Esc_Hit := TRUE;
WHILE( KeyPressed ) DO
READ( Kbd, Ch );
END;
UNTIL ( Async_Carrier_Detect ) OR
( Timed_Out ) OR
( Modem_Buzy ) OR
( Modem_NoC ) OR
( Esc_Hit );
IF Esc_Hit THEN
BEGIN
GoToXY( 1 , WhereY );
WRITE('*** ESC Pressed, Dialing Aborted.');
ClrEol;
(* Hang up the phone *)
HangUpPhone;
END
ELSE IF Timed_Out THEN
BEGIN
GoToXY( 1 , WhereY );
WRITE('*** Modem Timed Out, Dialing Aborted.');
ClrEol;
DELAY( One_Second_Delay );
END
ELSE IF Modem_Buzy THEN
BEGIN
GoToXY( 1 , WhereY );
WRITE('*** Line busy');
ClrEol;
(* Hang up the phone *)
HangUpPhone;
DELAY( One_Second_Delay );
END
ELSE IF Modem_NoC THEN
BEGIN
GoToXY( 1 , WhereY );
WRITE('*** No answer');
ClrEol;
(* Hang up the phone *)
HangUpPhone;
DELAY( One_Second_Delay );
END;
END (* Phone number gotten *);
Restore_Screen( Local_Save_5 );
Reset_Global_Colors;
IF ( Async_Carrier_Detect AND ( NOT Quit ) ) THEN
BEGIN (* Carrier detected *)
STimer := TimeOfDay;
REPEAT
Timed_Out := TimeDiff( Stimer , TimeOfDay ) > 3.0;
IF Async_Receive( Ch ) THEN
Modem_Mess := Modem_Mess + Ch;
UNTIL( Ch = CHR( CR ) ) OR ( Timed_Out );
IY := 0;
IF( LENGTH( Modem_Connect ) > 0 ) THEN
IY := POS( Modem_Connect , Modem_Mess );
IF ( IY > 0 ) THEN
BEGIN
I := IY + LENGTH( Modem_Connect ) + 1;
New_Baud := 0;
FOR J := I TO LENGTH( Modem_Mess ) DO
IF Modem_Mess[J] IN ['0'..'9'] THEN
New_Baud := New_Baud * 10 + ORD( Modem_Mess[J] ) -
ORD('0');
IF ( New_Baud <> Baud_Rate ) AND
( New_Baud > 0 ) THEN
BEGIN
Baud_Rate := New_Baud;
Async_Reset_Port( Comm_Port, Baud_Rate, Parity,
Data_Bits, Stop_Bits );
END;
END;
WRITELN;
WRITELN('Connection established at ',Baud_Rate,',',Parity,',',
Data_Bits,',',Stop_Bits);
END (* Carrier detected *);
(* Make sure phone hung up *)
IF Quit THEN
HangUpPhone;
END (* Dial_A_Number *);
(*----------------------------------------------------------------------*)
(* Redial_A_Number --- Redial last phone number dialed *)
(*----------------------------------------------------------------------*)
PROCEDURE Redial_A_Number;
(*----------------------------------------------------------------------*)
(* *)
(* Procedure: Redial_A_Number *)
(* *)
(* Purpose: Redials last number dialed (if any). *)
(* *)
(* Calling Sequence: *)
(* *)
(* Redial_A_Number; *)
(* *)
(* Calls: *)
(* *)
(* Dial_A_Number *)
(* TimeOfDay *)
(* TimeDiff *)
(* Dialer_Carrier_Detect *)
(* Clear_Window *)
(* *)
(*----------------------------------------------------------------------*)
VAR
RTimer : REAL;
DTimer : REAL;
PTimer : REAL;
OTimer : REAL;
Done : BOOLEAN;
Rchar : CHAR;
MDelay : REAL;
MDnew : REAL;
Ypos : INTEGER;
Local_Save_5 : Saved_Screen_Ptr;
Quit : BOOLEAN;
BEGIN (* Redial_A_Number *)
(* Only redial if no current session *)
Done := Dialer_Carrier_Detect OR ( Phone_Number = '' );
MDelay := Modem_Redial_Delay;
WHILE( NOT Done ) DO
BEGIN
(* Redial the number *)
Dial_A_Number( TRUE , Quit );
(* If connection established, done *)
Done := Async_Carrier_Detect;
(* Otherwise, wait for specified *)
(* modem delay *)
IF ( NOT Done ) THEN
BEGIN
Save_Screen( Local_Save_5 );
Draw_Menu_Frame( 10, 10, 60, 16, Menu_Frame_Color,
Menu_Text_Color, 'Redialing' );
RTimer := TimeOfDay;
Clear_Window;
Ypos := WhereY;
WRITELN(' Seconds to next redial: ', TRUNC( MDelay ) );
WRITE (' R = redial now Esc = stop C = change delay.');
Rchar := ' ';
PTimer := MDelay;
OTimer := PTimer;
REPEAT
IF PTimer <> OTimer THEN
BEGIN
GoToXY( 26 , YPos );
WRITE( TRUNC( PTimer ) );
ClrEol;
OTimer := PTimer;
END;
IF KeyPressed THEN
BEGIN
READ( Kbd , Rchar );
IF UpCase( Rchar ) = 'C' THEN
BEGIN
GotoXY( 1 , 3 );
WRITE (' Enter new delay: ');
ClrEol;
(*$I-*)
READLN( MDNew );
(*$I+*)
IF Int24Result = 0 THEN
MDelay := MDNew;
GoToXY( 1 , 3 );
ClrEol;
END
ELSE IF ( Rchar = CHR( ESC ) ) THEN
Rchar := 'X';
END;
DTimer := TimeDiff( RTimer , TimeOfDay );
PTimer := MDelay - DTimer;
IF PTimer <= 0.0 THEN
PTimer := 0.0;
UNTIL ( DTimer > MDelay ) OR
( UpCase( Rchar ) IN ['R','X'] );
Done := ( UpCase(Rchar) = 'X' );
Restore_Screen( Local_Save_5 );
Reset_Global_Colors;
END (* NOT Done *)
ELSE
BEGIN
Save_Screen( Local_Save_5 );
Draw_Menu_Frame( 10, 10, 60, 14, Menu_Frame_Color,
Menu_Text_Color + Blink, '' );
WRITELN('Connection established!!');
WRITE ('Hit any key to continue');
REPEAT
Menu_Beep;
DELAY( 3 * Tenth_Of_A_Second_Delay );
UNTIL( KeyPressed );
READ( Kbd , RChar );
IF ( RChar = CHR( ESC ) ) AND KeyPressed THEN
READ( Kbd, RChar );
Restore_Screen( Local_Save_5 );
Reset_Global_Colors;
END;
END (* NOT Done *);
END (* Redial_A_Number *);
(*------------------------- PIBDIALER --------------------------------*)
BEGIN (* PibDialer *)
(* Open phone file for later use *)
ASSIGN( Phone_File, Home_Dir + 'PIBTERM.FON' );
(*$I-*)
RESET( Phone_File );
(*$I+*)
(* Determine if dial or redial *)
CASE ReDial OF
FALSE: REPEAT
Dial_A_Number( FALSE , Quit );
Quit := Quit OR Script_File_Mode;
IF ( ReDial AND ( NOT Quit ) ) THEN
BEGIN
ReDial_A_Number;
Redial := FALSE;
END;
UNTIL ( Async_Carrier_Detect OR Quit );
TRUE: BEGIN
IF Phone_Number = '' THEN
Dial_A_Number( FALSE , Quit );
ReDial_A_Number;
END;
END (* CASE *);
(* Close phone file when done *)
(*$I-*)
CLOSE( Phone_File );
(*$I+*)
(* Reset timer if connection made *)
IF Async_Carrier_Detect THEN
Dialing_Start_Time := TimeOfDay;
END (* PibDialer *);